package com.loong.life.mq;

import com.loong.common.rabbitmq.dto.base.BusinessEventDto;
import com.loong.common.rabbitmq.dto.base.RepositoryEventDto;
import com.loong.common.rabbitmq.enums.BusinessEvent;
import com.loong.common.rabbitmq.producer.CustomMessagePostProcessor;
import com.loong.common.rabbitmq.producer.ExpirationMessagePostProcessor;
import com.loong.common.utils.TransformUtils;
import com.loong.global.constant.MQConstant;
import com.loong.global.dto.PhoneChargeDTO;
import com.loong.global.enums.mq.QueueEnums;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.QueueInformation;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Description:
 * @Author: LiuQun
 * @Date: 2020/12/22 10:02
 */
@Slf4j
@Component
public class PhoneChargeReport {

    @Resource(name = "defaultRabbitTemplate")
    private RabbitTemplate defaultRabbitTemplate;


    /**
     * 手机订单上报
     *
     * @param report
     */
    @Async
    public void report(BusinessEventDto report) {
        try {
            report.setData(TransformUtils.transform(report.getData(), PhoneChargeDTO.class));
            defaultRabbitTemplate.convertAndSend(
                    MQConstant.BASE_PREFIX+ QueueEnums.PHONE_CHARGE.getExchange()+MQConstant.BASE_SUFFIX.EXCHANGE,
                    MQConstant.BASE_PREFIX+QueueEnums.PHONE_CHARGE.getRouterKey()+MQConstant.BASE_SUFFIX.DELAY_ROUTE_KET,
                    report,
                    new ExpirationMessagePostProcessor(10000L));
        } catch (Exception ex) {
            log.error("上报手机充值信息日志发生异常", ex);
        }
    }
}
